%GLOBAL CWD; %LET CWD = %SUBSTR(%SYSGET(SAS_EXECFILEPATH), 1, %EVAL(%LENGTH(%SYSGET(SAS_EXECFILEPATH)) - %LENGTH(%SYSGET(SAS_EXECFILENAME)) - 1));
%INCLUDE "&CWD\TOOLS.SAS";

/* SET ELI & CLUSTER */
%LET ELI = FS011;
%LET CLUSTER = 01A;

/* IDENTIFYING HANDLE */
%LET COM = &ELI._&CLUSTER.;

/* ITEM-SPECIFIC RIGHT HAND SIDE VARIABLES */
%LET RHS= 
    B2 C2 C3 C99SP D2 D5 E2 E3 F2 F99SP BRAND1 BRAND2
    MNAMT MNAMTSQ
    ;

%LET STYR = 0201;
%LET FIRSTPER = 20&STYR;
%LET LASTPER = 200709;
%LET STDUM = D&STYR;
%LET RHYRS= D0202--D0709;

%LET NSPER = %COUNTMONTHS(&FIRSTPER, &LASTPER);
%LET NVEC = %EVAL(&NSPER + %COUNTWORDS(&RHS));

/* DEFINE ITEM-SPECIFIC PRICE EDITS */
%MACRO EDITS;
    IF PRICE<.05 THEN DELETE; 
    IF BSNS_TYPE_CD NE "";
    IF LNAMT =. THEN DELETE;
%MEND;

/* DEFINE ITEM-SPECIFIC DUMMIES */
%MACRO VARS;
    ARRAY SPECARRAY (*) A B C D E F ;
    DO COUNT=1 TO DIM(SPECARRAY);
        IF SPECARRAY(COUNT)="" THEN DELETE;
    END;
    IF SUBSTR(G99,1,5)="**********" THEN BRAND1=1; ELSE BRAND1=0;
    IF INDEX(G99,'**********') AND INDEX(G99,'LAKES') THEN BRAND2=1; ELSE BRAND2=0;
%MEND;

LIBNAME IN "&CWD\DATA";
LIBNAME OUT "&CWD\DATA";

FILENAME OUTLOGS "&CWD\OUTPUT\LOGINDEXES.XLS";
FILENAME OUTCONTS "&CWD\OUTPUT\LOGCONTRIBS.XLS";
FILENAME OUTDISCS "&CWD\OUTPUT\DISCOUNTS.XLS";
FILENAME OUTPCTLS "&CWD\OUTPUT\PCTLS.XLS";

%INCLUDE "&CWD\TABLESTOBUILD.SAS";
